import scanpy as sc

from pyfeasc.utils.integration import meta_feature_integration

if __name__ == '__main__':
	# 读取数据
	path_gse = "../../data/input/anndata/GSE96583.h5ad"
	adata = sc.read_h5ad(path_gse)
	adata.var_names_make_unique()
	
	# 过滤数据
	sc.pp.filter_cells(adata, min_genes=200)
	sc.pp.filter_genes(adata, min_cells=3)
	sc.pp.highly_variable_genes(adata, n_top_genes=2000, flavor="seurat_v3")
	adata = adata[:, adata.var.highly_variable]
	
	# 运行主流程，获取所有结果
	mf_embedding, mf_loading = meta_feature_integration(adata, batch_col="stim", method="pca")
	adata.obsm["X_integrated"] = mf_embedding
	print(adata.obsm["X_integrated"].shape)
	
	# 可视化
	sc.pp.neighbors(adata, use_rep="X_integrated")
	sc.tl.umap(adata)
	sc.pl.umap(adata, color=["stim", "cell"])
